#include <chrono>
#include <session.h>
#include <connection.h>
#include <iostream>
#include <thread>

using namespace std;

class Client:public Session {


	public:
		Client();
		void doSend(char type, uint32_t bounds, std::vector<char> &body) override;
		void doWork(const Protocal &data) override;

	private:
		Dispatcher dp;
};

Client::Client():Session(1),dp(this)
{
	dp.Create_Socket();
	auto cb = ([this](){
			
			std::string promote = "hello world";
			std::vector<char> bd(promote.begin(), promote.end());
			doSend('1', bd.size(), bd);
			});
	dp.Connect("127.0.0.1", 6665, cb);
	start(dp.GetTcpHandle());
}

void Client::doSend(char type, uint32_t bounds, std::vector<char> &body)
{
	Session::doSend(type, bounds, body);
}

void Client::doWork(const Protocal &data)
{
	cout << data.head.counter << endl;
	cout << data.head.id << endl;
	cout << data.head.len << endl;
}

int main(int argc, char* argv[]) {
	
	Client c;


	Dispatcher::Loop();
	return 0;
}
